from rusher import Rusher

class X8Rusher(Rusher):
  def __init__(self):
    super().__init__()
    self.url_list.extend([
      # Use sezhan8 as host
      'http://sezhan8.com/index.php?u=358107',  # Main account
      'http://sezhan8.com/index.php?u=21994756',
      'http://sezhan8.com/index.php?u=21994879',
      'http://sezhan8.com/index.php?u=22001889',
      'http://sezhan8.com/index.php?u=22001907',
      # Use cnxici8 as host
      'http://cnxici8.com/index.php?u=358107',  # Main account
      'http://cnxici8.com/index.php?u=21994756',
      'http://cnxici8.com/index.php?u=21994879',
      'http://cnxici8.com/index.php?u=22001889',
      'http://cnxici8.com/index.php?u=22001907',
      # Use sex8 as host
      'http://sex8.cc/index.php?u=358107',  # Main account
      'http://sex8.cc/index.php?u=21994756',
      'http://sex8.cc/index.php?u=21994879',
      'http://sex8.cc/index.php?u=22001889',
      'http://sex8.cc/index.php?u=22001907',
      ])

  def Request(self, url, proxy=None):
    req = self._BuildRequest(proxy)
    try:
      f = req.open(url)
      data = f.read()
    except:
      return False
    data = data.decode()  # Remember to decode the data!
    if 'sex8' not in data:
      return False
  
    info = f.info()
    set_cookies = info.get_all('Set-Cookie')
    cookie1 = str(set_cookies[0]).split(' ')[0]
    cookie2 = str(set_cookies[1]).split(';')[0]
    cookie = cookie1 + ' ' + cookie2
  
    req = self._BuildRequest(proxy)
    req.addheader('Cookie', cookie)
    req.addheader('Referer', url)
    try:
      f = req.open(url, 'ses=&fromuid=&time=')
      data = f.read()
    except:
      return False
    data = data.decode()
    if 'sex8' not in data:
      return False
    return True
